﻿/*
 * Auto Currency Converter
 * -------------------------------------------------------------------
 * Licensed under the GPLv3 license, see LICENSE in root for details.
 *
 * common.js
 *
 * Copyright (c) 2010 Thomas Klein
 */
function fetchConversionRates()
{
	xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",false);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
			var site = xmlhttp.responseXML;
			var elements = site.getElementsByTagName("Cube");
			localStorage["rate_eur"] = 1;
			for(var i=0; i<elements.length; i++)
			{
				if(elements[i].getAttribute("currency") == "USD")
					localStorage["rate_usd"] = elements[i].getAttribute("rate");
				if(elements[i].getAttribute("currency") == "JPY")
					localStorage["rate_jpy"] = elements[i].getAttribute("rate");
				if(elements[i].getAttribute("currency") == "GBP")
					localStorage["rate_gbp"] = elements[i].getAttribute("rate");
				if(elements[i].getAttribute("currency") == "CAD")
					localStorage["rate_cad"] = elements[i].getAttribute("rate");
			}
			localStorage["lastupdate"] = new Date().getTime();
		}
	}
	xmlhttp.send(null)
}